package com.oa.pm.controller;


import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.core.BaseController;
import com.oa.core.exception.BusinessException;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.pm.dto.CompanyDTO;
import com.oa.pm.dto.OrganizationDTO;
import com.oa.pm.dto.OrganizationUpdateDTO;
import com.oa.pm.service.IOrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/personnelmanagement")
@Api(description = "人事管理-人员管理")
public class PersonnelManagementController extends BaseController {

    private final IOrganizationService organizationService;

    public PersonnelManagementController(IOrganizationService organizationService) {
        this.organizationService = organizationService;
    }

    @PostMapping("/addOrganization")
    @CommonController
    @Description("新增组织结构")
    @ApiOperation(value = "新增组织结构")
    public Resp addOrganization(@ApiParam(value = "组织架构表对象") @RequestBody(required = false) OrganizationDTO organizationDTO) throws BusinessException {
        return organizationService.addOrganization(organizationDTO);
    }

    @PostMapping("/addCompany")
    @CommonController
    @Description("新增组织结构-公司")
    @ApiOperation(value = "新增组织结构-公司")
    public Resp addCompany(@ApiParam(value = "组织架构表对象") @RequestBody(required = false) CompanyDTO companyDTO) throws BusinessException {
        return organizationService.addCompany(companyDTO);
    }


//    @PostMapping("/findOrganizationByStructureAndCondition")
//    @CommonController
//    @Description("根据条件按层级查询组织架构")
//    @ApiOperation(value = "根据条件按层级查询组织架构")
//    public Resp findOrganizationByStructureAndCondition(@ApiParam(value = "组织架构名称,不传值则按层架查询所有的组织架构") @RequestParam(required = false) String organizationName) throws DataIsEmptyException {
//        return organizationService.findOrganizationByStructureAndCondition(organizationName);
//    }

    @PostMapping("/findOrganizationDetailsById")
    @CommonController
    @Description("根据组织架构主键id查询组织架构详情")
    @ApiOperation(value = "根据组织架构主键id查询组织架构详情")
    public Resp findOrganizationDetailsById(@ApiParam(value = "组织架构主键ID") @RequestParam(required = false) String id) throws DataIsEmptyException {
        return organizationService.findOrganizationDetailsById(id);
    }

    @PostMapping("/updateOrganization")
    @CommonController
    @Description("修改组织结构")
    @ApiOperation(value = "修改组织结构")
    public Resp updateOrganization(@ApiParam(value = "组织架构表对象") @RequestBody(required = false) OrganizationUpdateDTO organizationUpdateDTO) throws BusinessException {
        return organizationService.updateOrganization(organizationUpdateDTO);
    }

    @PostMapping("/deleteOrganization")
    @CommonController
    @Description("根据组织架构主键id删除组织架构")
    @ApiOperation(value = "根据组织架构主键id删除组织架构")
    public Resp deleteOrganization(@ApiParam(value = "组织架构主键ID") @RequestParam(required = false) String id) throws DataIsEmptyException, BusinessException {
        return organizationService.deleteOrganization(id);
    }


}


